//2009/08/24 00:55:45
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class MorselikeCode
{
public:
    string decrypt(vector <string> library, string message)
    {
		string msg;
		stringstream ss(message);
		string s;
		while(ss >> msg)
		{
			bool flag = false;
			string temp;
			for(int i=0; i<library.size(); i++)
			{
				if(msg == library[i].substr(2))
				{
					flag = true;
					temp = library[i][0];
					break;
				}
			}
			if(flag) s += temp;
			else s += "?";
		}
		return s;
    }
};
